home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / futils.arc / FWRITE.DOC < prev    next >
Text File  |  1991-04-28  |  8KB  |  268 lines

  1.  
  2. ********************************************************************
  3. ************************ FWRITE by Rex Kerr ************************
  4. ************************ Copyright (C) 1989 ************************
  5. ********************************************************************
  6.  
  7. This is a Turbo Pascal 5.5 unit written mostly in assembly
  8. language.  It has 12 routines for reading/writing and 7 that
  9. affect how the 12 other routines work.
  10.  
  11. ***
  12.  
  13. VramCh(x,y : byte; ch : char; attr : byte);
  14.  
  15. This writes the character ch in attribute attr at X,Y on the screen.
  16. Note that VramCh pays no attention to any windows that might be
  17. on the screen--all coordinates are absolute screen coordinates.
  18. If you use the CRT unit in your program, you can write in the
  19. current text color using the CRT variable TextAttr (like this:)
  20.  
  21. vramch(xpos,ypos,ch,textattr);  { Only textattr needs to stay the same
  22.                                   to write in TP's text color }
  23.  
  24. ***
  25.  
  26. GetVramCh(x,y : byte; var ch : char; attr : byte);
  27.  
  28. This reads the character and attribute at X,Y.  See VramCh.
  29.  
  30. ***
  31.  
  32. VramCharRpt(count : byte; x,y : byte; ch : char; attr : byte);
  33.  
  34. This repeats one character and attribute starting at x,y and
  35. repeating count times.  It is useful for clearing a portion of
  36. the screen, for example:
  37.  
  38. program clearwindow(windowx,windowy,windowx2,windowy2 : byte);
  39. var tempbyte : byte;
  40.     i : integer;
  41. begin
  42.      for i := windowy to windowy2 do
  43.      begin
  44.           tempbyte := (windowx2 - windowx) + 1;
  45.           vramcharrpt(tempbyte,windowx,i,' ',textattr);
  46.      end;
  47. end;
  48.  
  49. That procedure will fill the window (defined by windowx, windowy,
  50. windowx2, windowy2) with spaces in the current text attribute.
  51.  
  52. ***
  53.  
  54. VramLineCopy(count : byte; x,y : byte; x2,y2 : byte);
  55.  
  56. This copies count characters (and attributes) starting at X,Y
  57. and going to X2,Y2.  It works about the same as
  58.  
  59. procedure false_vramlcopy(count,x,y,x2,y2 : byte);
  60. var i,atr : byte;
  61.     ch : char;
  62. begin
  63.      for i := 0 to count-1 do
  64.      begin
  65.           getvramch(x+i,y,ch,attr);
  66.           vramch(x2+i,y2,ch,attr);
  67.      end;
  68. end;
  69.  
  70. except it is much much faster.
  71.  
  72. ***
  73.  
  74. VramWrit(x,y : byte; attr : byte; st : string);
  75.  
  76. This writes the string st in attribute attr starting at X,Y.
  77.  
  78. It will NOT scroll the screen up when it goes off the end of the
  79. last line, and it does not interpret chars #7,8,10 and 13.
  80.  
  81. ***
  82.  
  83. ClrVramLine(line : byte; attr : byte);
  84.  
  85. This clears the line specified with the attribute specified.
  86.  
  87. ***
  88.  
  89. ClrVram(attr : byte);
  90.  
  91. This clears the whole screen with the attribute specified.
  92.  
  93. ***
  94.  
  95. VramScroll(lines : shortint; x,y,w,h : byte; attr : byte);
  96.  
  97. This scrolls the defined window (that is, a window the same size as
  98. you would get with window(x,y,w,h); ) up the indicated number of
  99. lines.  New lines will be blank in the attribute attr.  To scroll
  100. the screen down, pass a negative number.
  101.  
  102. Note:  To save speed, scroll as many lines as possible at one time.
  103.  
  104. Instead of writing
  105.  
  106. vramscroll(1,1,1,80,25,7);
  107. vramwrit(1,25,7,'This is the');
  108. vramscroll(1,1,1,80,25,7);
  109. vramwrit(1,25,7,'slow way to');
  110. vramscroll(1,1,1,80,25,7);
  111. vramwrit(1,25,7,'scroll this.');
  112.  
  113. you should write
  114.  
  115. vramscroll(3,1,1,80,25,7);
  116. vramwrit(1,23,7,'This is the');
  117. vramwrit(1,24,7,'fast way to');
  118. vramwrit(1,25,7,'do this.');
  119.  
  120. ***
  121.  
  122. VramLine(x,y : byte; start,count : byte; var lin);
  123.  
  124. This is meant to write count chars and attrs (starting at X,Y on the
  125. screen (and start in lin)) from the predefined type, vram_line, which
  126. is defined as:
  127.  
  128. type vram_line = array[1..80][1..2] of byte;
  129.  
  130. in FWRITE.
  131. However, you can pass any variable you want...but be sure you don't
  132. overrun it.
  133.  
  134. ***
  135.  
  136. GetVramLine(x,y : byte; start,count : byte; var lin);
  137.  
  138. This does the same thing as VramLine, except it reads into lin
  139. instead of writing from it.
  140.  
  141. ***
  142.  
  143. PutVramSec(var scrn; x,y,w,h : byte; x2,y2 : byte);
  144.  
  145. This is meant to copy a window on the screen (x,y,w,h) from scrn
  146. (starting at x2,y2 in scrn).  Scrn is meant to be the predefined
  147. type Vram_ScrBuf, which is defined as
  148.  
  149. type Vram_ScrBuf = array[1..25] of Vram_Line;
  150.  
  151. but any variable large enough can be used.
  152.  
  153. ***
  154.  
  155. GetVramSec(var scrn; x,y,w,h : byte; x2,y2 : byte);
  156.  
  157. This is putvramsec's twin.  It does the same as putvramsec, except
  158. it reads from the screen instead of writes to it.
  159.  
  160. ***
  161.  
  162. Get_Display(var screenseg : word);
  163.  
  164. This returns $B000 if the monitor is monochrome, otherwise it
  165. assumes CGA and returns $B800.  It is normally used on the
  166. variable Vid_Mem_Start.  You can set Vid_Mem_Start yourself if
  167. you want to write to an EGA or VGA display, for example.
  168.       Card             Segment
  169.      Monochrome         $B000
  170.      CGA                $B800
  171.      EGA                $A000
  172.      VGA                $A000
  173.  
  174. Note: EGAs and VGAs start at $A000 in graphics mode.  I am not sure
  175.       where they start in "large" mode.  In CGA mode (80*25), they
  176.       start at $B800.
  177.  
  178. ***
  179.  
  180. SetVramOfs(ofst : word);
  181.  
  182. This sets the offset of screen memory.  For the real screen, it
  183. should always be 0.  However, you may want to define a "fake" screen.
  184. Assuming FakeBuf is an array at least 4000 bytes long, you can do
  185. this to set up a fake screen to read from and write to:
  186.  
  187.      vid_mem_start := seg(fakebuf);
  188.      setvramofs(ofs(fakebuf));
  189.  
  190. Now, all reads and writes will be to and from fakebuf, just like it
  191. was the real screen.  To write back to the old screen (assuming
  192. Get_Display works for you) you simply do:
  193.  
  194.      get_display(vid_mem_start);
  195.      setvramofs(0);
  196.  
  197. If get_display doesn't work, you'll have to save the old mode in
  198. a variable:
  199.  
  200. var a : word;
  201.     b : vram_scrbuf;
  202.  
  203. begin
  204.      vid_mem_start := $B500;   { Wierd display, but...           }
  205.      ( . . . )                 { Do some stuff                   }
  206.      a := vid_mem_start;       { Save the address                }
  207.      vid_mem_start := seg(b);  { Set the segment address         }
  208.      setvramofs(ofs(b));       { Set the offset address          }
  209.      ( . . . )                 { Write to b instead of screen    }
  210.      vid_mem_start := a;       { Get the old address back again  }
  211.      setvramofs(0);            { Now you can write to the screen }
  212. end.
  213.  
  214. ***
  215.  
  216. GetVramOfs : word;
  217.  
  218. This gets the current offset.
  219.  
  220. ***
  221.  
  222. SetVramMaxX(lines : byte);
  223.  
  224. This sets the length of the lines on the screen.  Useful for both
  225. "fake" screens which are smaller (50*20, maybe) or EGA and VGA modes
  226. where the lines are longer than normal.
  227.  
  228. ***
  229.  
  230. GetVramMaxX : byte;
  231.  
  232. This gets the set length of the lines on the screen.
  233.  
  234. ***
  235.  
  236. SetVramMaxY(lines : byte);
  237.  
  238. This sets the length of the screen in lines.  It isn't really used
  239. except in ClrVram.  The others never check to see if they are going
  240. off the end of the screen.
  241.  
  242. ***
  243.  
  244. GetVramMaxY : byte;
  245.  
  246. This gets the set length of the screen in lines.
  247.  
  248. ***
  249.  
  250. Two warnings:
  251.  
  252. 1) FWRITE will cause snow on snowy CGAs.  I haven't yet found out
  253. how to not cause snow and not slow down good monitors too much.
  254. 2) FWRITE never checks to see that you have valid parameters.  If
  255. your screen is 80*25 and to do vramch(90,30,ch,textattr), It will
  256. write the character out anyway.  This is usually fine for the real
  257. screen.  However, when you are writing to a "fake" screen, you have
  258. to be careful, because if you run over the end of the buffer, you
  259. will most likely be overwriting something you didn't want to.
  260.  
  261. Also note that FWRITE never moves the cursor, and always reads from
  262. absolute screen coordinates (i.e. 1,1 is always the top left corner
  263. of the screen, no matter what windows you set).
  264.  
  265. This is version 1.2 of FWRITE.  Version 1.0 had a bug in the
  266. scrolling routine.  The scrolling is now faster, and it works the
  267. right way, too.  To my knowledge, FWRITE is faster than any other
  268. units for Turbo Pascal that write directly to screen memory.